<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Validator;
use Symfony\Component\HttpKernel\Exception\HttpException; // 注意是抛出这个类型的异常。

class ApiRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;}


    // 主要是重写这个方法。
    protected function failedValidation(Validator $validator)
    {
        throw new HttpException(500, $validator->errors()->first());
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'server' => 'required',
            'game_id' => 'required',
            'product_version' => 'required',
            'ways_purchase' => 'required',
            'contact_details' => 'required'
        ];
    }

    public function messages()
    {
        return [
            'server.required' => '请选择服务器',
            'game_id.required' => '请填写游戏ID',
            'product_version.required' => '请选择商品版本',
            'ways_purchase.required' => '请选择购买',
            'contact_details.required' => '请填写联系方式',
        ];
    }

}
